package cn.itsource.web.controller;

import cn.itsource.domain.Employee;
import cn.itsource.domain.Menu;
import cn.itsource.serivce.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**--------------------------------------------------------
菜单相关
 --------------------------------------------------------**/
@Controller
public class MenuController {

    @Autowired
    private IMenuService menuService ;

    /**--------------------------------------------------------
    跳转主页
     --------------------------------------------------------**/
    @RequestMapping("/main")
    public String main(Model model, HttpSession session){
        //查询用户的的菜单，树状结构
        Employee employee = (Employee) session.getAttribute(LoginController.EMPLOYEE_IN_SESSION);

        List<Menu> userMenu = null;  //menuService.selectAllForTree();

        if(employee.isAdmin()){
            //测试代码
            userMenu = menuService.selectAllForTree();
        }else{

            menuService.selectMenuTreeByUserId(employee.getId());
        }
        model.addAttribute("menulist", userMenu);
        return "main";
    }
}
